<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAfterSaleOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('after_sale_orders', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('agent_id')->index()->comment('代理商 ID');
            $table->bigInteger('supplier_id')->index()->comment('供应商 ID');
            $table->bigInteger('order_id')->index()->comment('订单 ID');
            $table->char('order_numbering', 22)->index()->comment('普通订单编号 (type 2位)(YmdHis 14位)(随机字符串 6位)');
            $table->char('numbering', 22)->unique()->comment('售后订单编号 (type 2位)(YmdHis 14位)(随机字符串 6位)');
            $table->tinyInteger('type')->comment('售后类型; 1:退货 2:重发货 3:只退款 4:补偿');
            $table->unsignedBigInteger('refund_amount')->default(0)->comment('退货款');
            $table->unsignedBigInteger('compensation')->default(0)->comment('补偿款');
            $table->unsignedBigInteger('refund_shipping')->default(0)->comment('退运费');
            $table->string('reason')->default('')->comment('原因');
            $table->string('courier_company')->default('')->comment('快递公司');
            $table->string('return_order_numbering')->default('')->comment('退货单号');
            $table->date('return_time')->nullable()->comment('退货时间');
            $table->bigInteger('client_id')->default(0)->comment('买家 ID');
            $table->string('address')->default('')->comment('收货地址');

            $table->bigInteger('commodity_id')->comment('商品 ID');
            $table->bigInteger('commodity_activity_id')->comment('商品活动 ID');

            $table->tinyInteger('status')->default(1)->comment('处理状态; 1:待审核 2:跟进中 3:已通过 4:未通过 5:已取消');

            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('after_sale_orders');
    }
}
